import java.io.*;

public class Dtest {
    public static void main(String[] args) {
        String s = new String();
        String s1 = new String();
        try {
            File f = new File("D:\\123.txt");
            if (f.exists()) {
                System.out.print("文件存在");
            } else {
                System.out.print("文件不存在");
                f.createNewFile();//不存在则创建
            }
            BufferedReader input = new BufferedReader(new FileReader(f));
            while ((s = input.readLine()) != null) {
                s1 += s + "\n";
            }
            System.out.println(s1);
            input.close();
            s1 += "添加的内容!";
            BufferedWriter output = new BufferedWriter(new FileWriter(f));
            output.write(s1);
            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}